#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
struct node{
    int gf;
    bool ex;
    bool fig;
}a[N];
bool cmp(node x,node y){
    return x.gf < y.gf;
}
int main(){
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        int k;
        cin >> k;
        a[i].gf = k;
        a[i].ex = true;
        a[i].fig = false;
    }
    sort(a+1,a+1+n,cmp);
    int maxn = a[n].gf,num = 0;
    for(int i=n;i>=1;i--){
        if(a[i].gf == maxn){
            num++;
        }
    }
    for(int i=n-num;i>=2;i--){
        if(a[i].ex && a[i-1].ex){
            if(!a[i].fig && a[i].gf > a[i-1].gf){
                a[i].fig = true;
                a[i-1].ex = false;
            }
        }
    }
    for(int i=1,j=n-num; i <= n-num && i<=j ;i++,j--){
        if(a[i].ex == false)
        {
            j++;
            continue;
        }
        if(a[i].gf < a[j].gf && a[j].fig == true && a[i].ex == true && a[j].ex == true){
            a[i].ex = false,a[j].fig = true;
        }else{
            i--;
        }
    }
    int res = 0;
    for(int i=1;i<=n-num;i++){
        if(a[i].ex == true){
            res ++;
        }
    }
    if(res <= num){
        cout << num;
    }else{
        cout << num + res - num;
    }
    return 0;
}
